package com.example.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.model.dtos.PageResult;
import com.example.model.dtos.R;
import com.example.service.InFormService;
import com.example.service.OutFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 查询统计控制类
 */
@RestController
@RequestMapping("statistics/statistics/")
public class StatisticsController {

    @Autowired(required = false)
    InFormService inFormService;

    @Autowired(required = false)
    OutFormService outFormService;

    /**
     * 获取所有出库表单
     */
    @RequestMapping("getOutForm")
    public R<PageResult> getOutForm(@RequestBody Map<String,String> map){
        String pageStr = map.get("current");
        String pageSizeStr = map.get("size");
        String outFormId = map.get("outFormId");
        String startDate = map.get("startDate");
        String endDate = map.get("endDate");
//        若为空，则查询第一页，每页10条
        if (StringUtils.isBlank(pageStr)){
            pageStr="1";
        }
        if (StringUtils.isBlank(pageSizeStr)){
            pageSizeStr="10";
        }
        Integer page = Integer.parseInt(pageStr);
        Integer pageSize = Integer.parseInt(pageSizeStr);



        PageResult pageResult = outFormService.getAllOutForm(page,pageSize,outFormId,startDate,endDate);
        return R.success(pageResult);
    }

    /**
     * 获取所有入库表单
     */
    @RequestMapping("getInForm")
    public R<PageResult> getInForm(@RequestBody Map<String,String> map){
        String pageStr = map.get("current");
        String pageSizeStr = map.get("size");
        String inFormId = map.get("inFormId");
        String startDate = map.get("startDate");
        String endDate = map.get("endDate");
//        若为空，则查询第一页，每页10条
        if (StringUtils.isBlank(pageStr)){
            pageStr="1";
        }
        if (StringUtils.isBlank(pageSizeStr)){
            pageSizeStr="10";
        }
        Integer page = Integer.parseInt(pageStr);
        Integer pageSize = Integer.parseInt(pageSizeStr);



        PageResult pageResult = inFormService.getAllInForm(page,pageSize,inFormId,startDate,endDate);
        return R.success(pageResult);
    }

}
